package models

import "github.com/astaxie/beego"

type JsonResponse struct {
	Code int `json:"code"`
	Message string `json:"message"`
	Data interface{} `json:"data"`
}

func (this *JsonResponse)Success()  {
	this.Code = 200
}

func (this *JsonResponse) ToSuccess(output *beego.Controller,data interface{})  {
	this.Code = 200
	this.Data = data
	this.Message = "OK"
	output.Data["json"] = this
	output.ServeJSON()
}

func (this *JsonResponse)Fail(msg string)  {
	this.Code = -1
	this.Message = msg
}

func (this *JsonResponse)ToFail(output *beego.Controller,msg string)  {
	this.Code = -1
	this.Message = msg
	output.Data["json"] = this
	output.ServeJSON()
}

func NewResponse() *JsonResponse {
	var response=new(JsonResponse)
	return response
}